package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Daily extends BaseDomain{

    public static final int STATUS_FORBID = -1; // 内容不符合,禁用状态
    public static final int STATUS_NORMAL = 0; // 草稿
    public static final int STATUS_WAITING = 1; // 待审核
    public static final int STATUS_RELEASE = 2; // 审核通过


    private String title;//标题

    private User author;//作者
    
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;//创建时间
    
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;//发布时间

    private String coverUrl;//封面

    private Integer status = STATUS_NORMAL;//状态,默认为草稿状态

    private DailyContent content;


    public String getJsonString(){
        Map<String,Object> map= new HashMap<>();
        map.put("title",title);
        if (author != null) {
            map.put("source",author.getNickName());
        }
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }

    public String getStatusDisplay(){
        if(status == STATUS_NORMAL){
            return "草稿";
        }else if(status == STATUS_WAITING){
            return "待审核";
        }else if(status == STATUS_RELEASE){
            return "已发布";
        }else if(status == STATUS_FORBID){
            return "禁止发布";
        }
        return "";
    }
}